package com.example.demo.domain;

import com.example.demo.format.TreeFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.ibatis.type.Alias;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Alias("ResourceEntity")
@ApiModel("资源")
public class ResourceEntity implements TreeFormat<ResourceEntity, Long>, Serializable {
    private static final long serialVersionUID  = 6492238795597106121L;
    @ApiModelProperty("ID")
    private Long id;
    @ApiModelProperty("资源类型")
    private Integer resourceType;
    @ApiModelProperty("关联资源主键")
    private String resourceKey;
    @ApiModelProperty("关联资源父级的主键")
    private String resourceParentKey;
    @ApiModelProperty("对象id-用户id/用户组id")
    private Long objectId;
    @ApiModelProperty("操作权限json字符串")
    private String operationCode;
    @ApiModelProperty("子元素")
    private List<ResourceEntity> children = new ArrayList<>();
    @ApiModelProperty("资源名称")
    private String name;
    @ApiModelProperty("是否和用户直接关联，1直接关联")
    private Integer  isDirectRelate  = 1;
    @ApiModelProperty("是否选中")
    private boolean checked = false;
    @ApiModelProperty("操作权限列表")
    private List<Map<String, Object>> operationCodeList = new ArrayList<>();

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public Long getParentId() {
        return null;
    }

    @Override
    public void addChildren(ResourceEntity child) {
        if (child != null) {
            this.children.add(child);
        }
    }

    public void setChildren(List<ResourceEntity> children) {
        if (children != null) {
            this.children = children;
        } else {
            this.children.clear();
        }
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((resourceKey == null) ? 0
            : resourceKey.hashCode());
        result = prime * result + ((resourceKey == null) ? 0
            : resourceKey.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        ResourceEntity other = (ResourceEntity) obj;
        if (resourceKey == null) {
            if (other.resourceKey != null) {
                return false;
            }
        } else if (!resourceKey.equals(other.resourceKey)) {
            return false;
        }
        if (resourceType == null) {
            if (other.resourceType != null) {
                return false;
            }
        } else if (!resourceType.equals(other.resourceType)) {
            return false;
        }
        return true;
    }
    public void setId(Long id) {
        this.id = id;
    }

    public Integer getResourceType() {
        return resourceType;
    }

    public void setResourceType(Integer resourceType) {
        this.resourceType = resourceType;
    }

    public String getResourceKey() {
        return resourceKey;
    }

    public void setResourceKey(String resourceKey) {
        this.resourceKey = resourceKey;
    }

    public String getResourceParentKey() {
        return resourceParentKey;
    }

    public void setResourceParentKey(String resourceParentKey) {
        this.resourceParentKey = resourceParentKey;
    }

    public Long getObjectId() {
        return objectId;
    }

    public void setObjectId(Long objectId) {
        this.objectId = objectId;
    }

    public String getOperationCode() {
        return operationCode;
    }

    public void setOperationCode(String operationCode) {
        this.operationCode = operationCode;
    }

    public List<ResourceEntity> getChildren() {
        return children;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getIsDirectRelate() {
        return isDirectRelate;
    }

    public void setIsDirectRelate(Integer isDirectRelate) {
        this.isDirectRelate = isDirectRelate;
    }

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    public List<Map<String, Object>> getOperationCodeList() {
        return operationCodeList;
    }

    public void setOperationCodeList(List<Map<String, Object>> operationCodeList) {
        this.operationCodeList = operationCodeList;
    }

    @Override
    public String toString() {
        return "ResourceEntity{" +
            "id=" + id +
            ", resourceType=" + resourceType +
            ", resourceKey='" + resourceKey + '\'' +
            ", resourceParentKey='" + resourceParentKey + '\'' +
            ", objectId=" + objectId +
            ", operationCode='" + operationCode + '\'' +
            ", children=" + children +
            ", name='" + name + '\'' +
            ", isDirectRelate=" + isDirectRelate +
            ", checked=" + checked +
            ", operationCodeList=" + operationCodeList +
            '}';
    }
}
